package com.controller;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author 惊云
 * @date 2023/4/15 22:07
 */
@RestController
@RequestMapping("instance")
public class ServiceInstanceController implements ApplicationContextAware {
    
    private ApplicationContext applicationContext;

//    @Autowired
//    private HelloService helloService;

    @Autowired
    private DiscoveryClient discoveryClient;

    @RequestMapping("get-all")
    public String getInstance(){
        Map<String, GlobalFilter> beansOfType = applicationContext.getBeansOfType(GlobalFilter.class);
        return discoveryClient.getServices().toString();
    }


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
